#include <bits/stdc++.h>
using namespace std;
class Solution {
    public:
        vector<int> findAnagrams(string s, string p) {
            vector<int> ret;
            if(s.size()<p.size())return ret;
            vector<int> hashs(26,0),hashp(26,0);
            int lenp=p.size();
            for(char& c:p)
            {
                hashp[c-'a']++;
            }
            for(int i=0;i<lenp;i++)
            {
                hashs[s[i]-'a']++;
            }
            if(hashs==hashp)ret.push_back(0);
            for(int i=lenp;i<s.size();i++)
            {
                //移除左端点
                hashs[s[i-lenp]-'a']--;
                //移动右端点
                hashp[s[i]-'a']++;
                if(hashs==hashp)ret.push_back(i-lenp+1);
            }
        }
    };
int main()
{
    string s="cbaebabacd",p="abc";
    auto it=Solution().findAnagrams(s,p);
    for(auto& x:it)cout<<x<<" ";
    cout<<endl;
    return 0;
}